$stsadm = $env:CommonProgramFiles + "\Microsoft Shared\Web Server Extensions\12\BIN\stsadm.exe";
$wsp = "uaks.wsp";

if ($args.length -gt 0) {
	if ($args[0] -ne $null -and $args[0].StartsWith('http') -eq $true) { $url = $args[0]; }
	if ($url -eq $null) { $stop = $args[0]; } else { $stop = $args[1]; }
}


Write-Host "";
if ($url -eq $null) { 
	Write-Host "Retracting $wsp...";
	& $stsadm -o retractsolution -name $wsp -immediate;
}else{
	Write-Host "Retracting $wsp from $url...";
	& $stsadm -o retractsolution -name $wsp -url $url -immediate;
}
& $stsadm -o execadmsvcjobs;
if ($stop -eq 'retract') { return; }


Write-Host "Deleting $wsp...";
& $stsadm -o deletesolution -name $wsp;
& $stsadm -o execadmsvcjobs;
if ($stop -eq 'delete') { return; }


Write-Host "Adding $wsp...";
& $stsadm -o addsolution -filename $wsp;
& $stsadm -o execadmsvcjobs;
if ($stop -eq 'add') { return; }


if ($url -eq $null) { 
	Write-Host "Deploying $wsp...";
	& $stsadm -o deploysolution -name $wsp -allowgacdeployment -force -immediate;
}else{
	Write-Host "Deploying $wsp to $url...";
	& $stsadm -o deploysolution -name $wsp -url $url -allowgacdeployment -force -immediate;
}
& $stsadm -o execadmsvcjobs;


Write-Host "Done!";
Write-Host "";
